package com.project.service;

import com.project.common.utils.MyPageHelper;
import com.project.dao.CourseMapper;
import com.project.dao.CourseTeachMapper;
import com.project.entity.Course;
import com.project.entity.CourseTeach;
import com.project.myBeans.TeacherInfoDetail;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(rollbackFor = {Exception.class})
@Service
public class CourseTeachServiceImpl extends BaseService implements CourseTeachService {

    @Autowired
    CourseTeachMapper courseTeachMapper;

    @Autowired
    CourseMapper courseMapper;

    @Autowired
    CourseService courseService;

    @Override
    public void add(CourseTeach courseTeach) {
        courseTeachMapper.insertSelective(courseTeach);
    }

    @Override
    public List<TeacherInfoDetail> findTeachersByCourseid(Integer courseid) {
        return courseTeachMapper.selectTeachersByCourseid(courseid);
    }

    @Override
    public CourseTeach findById(Integer id) {
        return courseTeachMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Course> findCourseListByTeacherid(Integer teacherid) {
        List<Course> courseList = courseTeachMapper.selectCoursesByTeacherid(teacherid);
        return courseList;
    }

    @Override
    public List<CourseTeach> findByCondition(CourseTeach courseTeach) {
        MyPageHelper.setPageParam(courseTeach);
        return courseTeachMapper.selectByCondition(courseTeach);
    }

    @Override
    public List<Integer> findCoursesDistinctByTeacherid(Integer teacherid) {
        List<Integer> ids = courseTeachMapper.selectCoursesDistinctByTeacherid(teacherid);
        return ids;
    }

    @Override
    public int updateByPrimaryKeySelective(CourseTeach courseTeach) {
        return courseTeachMapper.updateByPrimaryKeySelective(courseTeach);
    }
}
